package likou.offer;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/7/30  14:49
 */
public class _03 {
    public static void main(String[] args) {
        int ww[] = {2, 3, 1, 0, 2, 5, 3};
        System.out.println(findRepeatNumber2(ww));
    }

    public static int findRepeatNumber(int[] nums) {
        int temp;
        for (int i = 0; i < nums.length; i++) {
            while (nums[i] != i) {
                if (nums[i] == nums[nums[i]]) {
                    return nums[i];
                }
                temp = nums[i];
                nums[i] = nums[temp];
                nums[temp] = temp;
            }
        }
        return -1;
    }

    public static int findRepeatNumber2(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            while (i != nums[i]) {
                if (nums[i] == nums[nums[i]]) {
                    return nums[i];
                }
                int temp = nums[nums[i]];
                nums[nums[i]] = nums[i];
                nums[i] = temp;
            }
        }
        return -1;
    }
}
